<template>
<a-drawer
    :destroyOnClose="true"
    :title="title"
    placement="right"
    :closable="true"
    :visible="visible"
    :maskClosable="true"
    :width="800"
    @close="close">
        <a-spin :spinning="confirmLoading">
             <a-tag style="margin-bottom: 2px;font-size:14px;" color="#0db76d">快递信息</a-tag>
            <LForm  ref="packageForm" :formAttributes="packageFormAttributes" :labelCol="labelCol" :wrapperCol="wrapperCol"></LForm>
            <a-tag style="margin-bottom: 2px;font-size:14px;" color="#0db76d">发票信息</a-tag>
             <LForm ref="LForm" :formAttributes="formAttributes" :labelCol="labelCol" :wrapperCol="wrapperCol"></LForm>
        </a-spin>
        

      <div class="drawer-bootom-button" v-if="localIsShowBootomButton">
            <a-button shape="round" @click="close" style="margin-right: .8rem">取消</a-button>
            <a-button shape="round" @click="ok" type="primary" >开票</a-button>
        </div>
    </a-drawer>
    
</template>

<script>
import LForm from '@/components/lt/form/LForm'
import pick from 'lodash.pick'
import request from '@/utils/request'
import moment from 'moment'
import defaultSettings from '@/config/defaultSettings'

export default {
    name:'userInvoiceForm',
    components:{LForm},
    props:{
        labelCol:{
            type:Object,
            default:function(){
                return {sm: { span:8 }}
            }
        },
        wrapperCol:{
            type:Object,
            default:function(){
                return {sm: { span: 16 }}
            }
        },
        isShowBootomButton:{
            type:Boolean,
            default:true
        }
      
    },
    data(){
        return{
            moment,
            title:'详情',
            visible:false,
            width:document.documentElement.clientWidth-208,
            confirmLoading:false,
            localIsShowBootomButton:this.isShowBootomButton,//是否显示提交按钮
            model:{},
            packageFormAttributes:{
              type:'',//collapse,tabs
              formItems:[
                {
                  title:'标签一',
                  columns:1,
                  fields:[
                    {field:'packageNo',label:'快递单号',component:'input',rules: [{required: false, message: '不能为空'}],disabled:true},
                    {field:'orderTime',label:'下单时间',component:'time',rules: [{required: false, message: '不能为空'}],disabled:true},
                    {field:'startStation',label:'发运站',component:'select',rules: [{required: false, message: '不能为空'}],dictCode:defaultSettings.数据字典.客运站下拉,disabled:true},
                    {field:'endStation',label:'到达站',component:'select',rules: [{required: false, message: '不能为空'}],dictCode:defaultSettings.数据字典.客运站下拉,disabled:true},
                    {field:'senderName',label:'托运人姓名',component:'input',rules: [{required: false, message: '不能为空'}],disabled:true},
                    {field:'senderPhone',label:'托运人电话',component:'input',rules: [{required: false, message: '不能为空'}],disabled:true},
                    {field:'consigneeName',label:'收件人姓名',component:'input',rules: [{required: false, message: '不能为空'}],disabled:true},
                    {field:'consigneePhone',label:'收件人电话',component:'input',rules: [{required: false, message: '不能为空'}],disabled:true},
                    {field:'goodsName',label:'物品名称',component:'input',rules: [{required: false, message: '不能为空'}],disabled:true},
                    {field:'goodsNum',label:'物品数量',component:'input',rules: [{required: false, message: '不能为空'}],disabled:true},
                    {field:'goodsFreight',label:'运费',component:'inputNumber',rules: [{required: false, message: '不能为空'}],disabled:true},
                  ]
                },
              ]

            },
            packageInfo:{},
            formAttributes:{
              type:'',//collapse,tabs
              formItems:[
                {
                  title:'标签一',
                  columns:1,
                  fields:[
                    {field:'invoiceTitle',label:'发票抬头',component:'input',rules: [{required: true, message: '不能为空'}],disabled:true},
                    {field:'invoiceNo',label:'纳税人识别号',component:'input',rules: [{required: true, message: '不能为空'}],disabled:true},
                    {field:'userNo',label:'手机号',component:'input',rules: [{required: true, message: '不能为空'}],disabled:true},
                    {field:'createTime',label:'申请时间',component:'input',rules: [{required: true, message: '不能为空'}],disabled:true},
                  ]
                },
              ]

            }
        }
    },
    created(){
    },
    computed:{
       
    },
    watch:{
        
    },
    methods:{
      
        edit (record) {
            this.visible = true;
            this.model = Object.assign({}, record)
            if(this.model.invoiceStatus=="1"){
                this.localIsShowBootomButton=true
            }else{
                this.localIsShowBootomButton=false
            }


            this.$nextTick(() => {
                this.getForm().setFieldsValue(pick(this.model,'invoiceTitle','invoiceNo','userNo', 'createTime'))
                
            })
            this.queryPackage()
            
        },
        ok(){
           let that = this
            this.getForm().validateFields((err, values) => {
                if (!err) {
                    that.confirmLoading = true
                    let formData = Object.assign(this.model, values);
                    request({url: '/KhyUserInvoiceController/Billing',method: 'post',data: formData}).then((res)=>{
                        if(res.success){
                            that.$message.success(res.message)
                            that.close()
                        
                        }else{
                            that.$message.warning(res.message)
                        }
                    }).finally(() => {
                        that.confirmLoading = false;
                    })
                    
                }
            })

        },
        close () {
            this.$emit('close');
            this.visible = false;
        },
        /**
         * 获取form对象
         */
        getForm(){
            return this.$refs.LForm.form
        },
        changeEventHandler(changeItem){

            
        },
        clickEventHandler(field,form){
           
        },
        setIsShowBootomButton(isShow){
            this.localIsShowBootomButton = isShow
        },
        queryPackage(){
            if(!this.model.packageId){
                return false
            }

            request.get('/KhyPackageController/queryKhyPackageById',{params:{keyId:this.model.packageId}}).then(res=>{
                if(res.success){
                    this.packageInfo=res.result
                    this.$nextTick(() => {
                        this.$refs.packageForm.form.setFieldsValue(pick(this.packageInfo,'packageNo','orderTime','startStation','endStation','senderName',
                        'senderPhone','consigneeName','consigneePhone','goodsName','goodsNum','goodsFreight',))
                    })
                }else{
                    this.$message.warning(res.message);
                }
            })
        }

        
    }

}
</script>

<style  scoped>
  .drawer-bootom-button {
    position: absolute;
    z-index: 999999;
    bottom: 0;
    width: 100%;
    /* border-top: 1px solid #e8e8e8; */
    padding: 10px 16px;
    text-align: right;
    left: 0;
    background: #fff;
    border-radius: 0 0 2px 2px;
  }

</style>